package com.chen.springboot.mapper.uniapp;

import com.chen.springboot.common.handler.JsonListTypeHandler;
import com.chen.springboot.dto.uniapp.CategoryItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryItemMapper {

    @Select("SELECT id, alt, pictures, target, title, type FROM category_items")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "alt", column = "alt"),
            @Result(property = "pictures", column = "pictures", typeHandler = JsonListTypeHandler.class),
            @Result(property = "target", column = "target"),
            @Result(property = "title", column = "title"),
            @Result(property = "type", column = "type")
    })
    List<CategoryItem> findAllCategoryItems();

    @Select("SELECT id, alt, pictures, target, title, type FROM category_items WHERE title LIKE CONCAT('%', #{keyword}, '%')")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "alt", column = "alt"),
            @Result(property = "pictures", column = "pictures", typeHandler = JsonListTypeHandler.class),
            @Result(property = "target", column = "target"),
            @Result(property = "title", column = "title"),
            @Result(property = "type", column = "type")
    })
    List<CategoryItem> searchCategoryItemsByKeyword(String keyword);
}
